home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / STRINGS.SWG / 0003_COMMA.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  70 lines

  1. { CB> ...I work For a bank and would like to create a Program to
  2.  CB> maintain better Record of our Cashier Checks and also any
  3.  CB> stop payments on them..I have done very little Programming
  4.  CB> on pascal. Ok here goes:
  5.  CB>         I would like to make the input of numbers to move
  6.  CB>         from a fixed point to the left and insert commas
  7.  CB>         every three digits For monetary figures?
  8.  
  9. You will need to set up a dedicated Character by Character input routine using
  10. ReadKey and controlling the display yourself.  After each Character is entered
  11. examine it and determine whether or not to add a comma.  The following very
  12. simple (and untested) routine demonstrates this.
  13.  
  14. For a better way to do such input find and download TCSEL003.* from a PDN node
  15. near you and study the KEYINPUT Unit.  You may be able to modify it to do
  16. exactly what you want or perhaps use it as a guide to producing your own
  17. "bullet proof" input routine.
  18. }
  19. Uses
  20.   Crt;
  21.  
  22. Function LastPos(ch : Char; S : String): Byte;
  23.   { Returns the last position of ch in S or zero if ch not in S }
  24.   Var
  25.     x   : Word;
  26.     len : Byte Absolute S;
  27.   begin
  28.     x := succ(len);
  29.     Repeat
  30.       dec(x);
  31.     Until (x = 0) or (S[x] = ch);
  32.     LastPos := x;
  33.   end;  { LastPos }
  34.  
  35.  
  36. Procedure GetNumber(fieldwidth: Byte);
  37.   Var ch : Char;
  38.       x,y: Byte;
  39.       i  : Word;
  40.       st : String;
  41.   begin
  42.     st := '';
  43.     Write('Enter a number: ');
  44.     x := WhereX;
  45.     y := WhereY;
  46.     Repeat
  47.       ch := ReadKey;
  48.       Case ch of
  49.         '0'..'9': begin
  50.                     if LastPos(',',st) = length(st)-3 then
  51.                       st := st + ',';
  52.                     st := st + ch;
  53.                   end;
  54.         #8      : begin
  55.                     delete(st,length(st),1);
  56.                     if st[length(st)] = ',' then
  57.                       delete(st,length(st),1);
  58.                   end;
  59.         #13     : Exit;
  60.       end;
  61.       gotoXY(x,y);
  62.       Write(st:fieldwidth);
  63.     Until False;
  64.   end;
  65.  
  66. begin
  67.   Writeln;
  68.   Writeln;
  69.   getnumber(14);
  70. end.